import 'package:cat_eye/util/util.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';

/*
* @Package: util
* @ClassName: photo_preview_widget
* @Author: szj
* @CreateDate: 8/5/21 10:30 AM
* TODO 图片预览Widget
*/
class PhotoPreViewWidget extends StatefulWidget {
  //图片Url集合
  final List<String> urlList;

  const PhotoPreViewWidget({Key key, @required this.urlList}) : super(key: key);

  @override
  _StatefulWidgetState createState() => _StatefulWidgetState();
}

class _StatefulWidgetState extends State<PhotoPreViewWidget> {
  int index = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(children: [
        PhotoViewGallery.builder(
          itemCount: widget.urlList.length,
          builder: (BuildContext context, int index) {
            this.index = index;
            return PhotoViewGalleryPageOptions(
              imageProvider: NetworkImage(widget.urlList[index]),
              //图片缩小一点
              initialScale: PhotoViewComputedScale.contained * 0.8,
            );
          },
          loadingBuilder: (context, event) => Center(
            //加载进度条
            child: CupertinoActivityIndicator(
             radius: 30,
             animating: true,
            ),
          ),
          onPageChanged: (index) {
            this.index = index;
            setState(() {});
          },
          // ),
        ),
        Positioned(
            right: 50,
            top: 80,
            child: text("${index + 1} / ${widget.urlList.length}",
                fontColor: Colors.white)),
      ]),
    );
  }
}
